class Solution {
public:
    bool issame(TreeNode* root, TreeNode* subRoot)
    {
        if (root == nullptr && subRoot == nullptr)
            return true;
        if (root == nullptr || subRoot == nullptr)
            return false;
        if (root->val != subRoot->val)
            return false;
        return issame(root->left, subRoot->left) && issame(root->right, subRoot->right);
    }

    bool isSubtree(TreeNode* root, TreeNode* subRoot)
    {
        if (root == nullptr)
            return false;
        if (root->val == subRoot->val && issame(root, subRoot))
            return true;
        return isSubtree(root->left, subRoot) || isSubtree(root->right, subRoot);
    }
};